package com.franklin.ideaplugin.easytesting.ui.execute;

import com.google.common.collect.Lists;
import com.intellij.psi.PsiParameter;
import org.jetbrains.annotations.NotNull;

import java.util.List;
import java.util.Objects;

/**
 * @author Ye Junhui
 * @since 2023/7/2 13:34
 */
public class ParameterFormProviderFactory implements IParameterFormProvider {

    private final List<IParameterFormProvider> parameterFormProviderList = Lists.newArrayList(
            new BooleanClassParameterFormProvider(),
            new EnumClassParameterFormProvider(),
            new DateClassParameterFormProvider(),
            new FileClassParameterFormProvider(),
            new JsonParameterFormProvider(),
            new StringParameterFormProvider(),
            new NormalParameterFormProvider()
    );

    private final NormalParameterFormProvider normalParameterFormProvider = new NormalParameterFormProvider();

    @Override
    public boolean isTarget(@NotNull Object defaultValue) {
        return true;
    }

    @Override
    public ParameterTextComponent getForm(PsiParameter psiParameter, Object defaultValueOfPsiType, Object defaultValue) {
        if (Objects.isNull(defaultValueOfPsiType)){
            defaultValueOfPsiType = defaultValue;
        }
        if (Objects.isNull(defaultValueOfPsiType)){
            return normalParameterFormProvider.getForm(psiParameter,"","");
        }
        for (IParameterFormProvider parameterFormProvider : parameterFormProviderList) {
            if (parameterFormProvider.isTarget(defaultValueOfPsiType)){
                return parameterFormProvider.getForm(psiParameter,defaultValueOfPsiType,defaultValue);
            }
        }
        return null;
    }
}
